const HtmlWebpackPlugin = require('html-webpack-plugin');//以一个html为模板复制一个新的html，引入JS文件
const path = require('path');//


module.exports = {
  mode: 'production',
  devServer: {
    port: 3333,
  },
  entry: './src/main.js',
  output: {
    clean:true,
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
  },


  plugins: [new HtmlWebpackPlugin({
    template:'./public/index.html'
  })],

  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },

      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          'style-loader',
          'css-loader',
          'less-loader',
        ],
      },
      {
        test: /\.(png|jpg|gif|jpeg)$/i,
        type:'asset'
      },
      {
        //不需要处理字体文件，直接原文件输出即可
        
        test: /\.(eot|svg|ttf|woff|woff2)$/i,
        type: 'asset/resource',
        generator: {
          filename:'font/[name].[hash:6][ext]'
        }
      },
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ],
  },
};